package Leetcode第二期;

/**
 * @author : K k
 * @date : 10:23 2020/9/20
 */
public class x的平方根_69 {
    public int mySqrt(int x) {
        int l=0,r=x;
        int ans=-1;
        while (l<=r){
            int mid=l+(r-l)/2;
            if((long)mid*mid <= x){
                ans=mid;
                l=mid+1;
            }else {
                r=mid-1;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        x的平方根_69 x=new x的平方根_69();
        System.out.println(x.mySqrt(4));
    }
}
